import {
  levels,
  question_types,
  QuestionVo,
} from "@/modules/question/api/question";
import { MaProTableColumns } from "@mineadmin/pro-table";
import { ElTag } from "element-plus";

export const getTableSchema = (t): MaProTableColumns[] => {
  return [
    {
      type: "selection",
      label: () => t("crud.selection"),
    },
    // 索引序号列
    { type: "index" },
    {
      label: () => t("question-manage.group"),
      prop: "group.name",
      cellRender({ row }) {
        return <ElTag>{row.group.name}</ElTag>;
      },
    },
    {
      label: () => t("question-manage.level"),
      prop: "level",
      minWidth: 120,
      cellRender({ row }) {
        const lv = levels.find((lv) => lv.level == row.level);
        return <ElTag>{lv?.name || row.level}</ElTag>;
      },
    },
    {
      label: () => t("question-manage.type"),
      prop: "type",
      minWidth: 120,
      cellRender({ row }) {
        const type =
          question_types.find((type) => type.code == row.type)?.name ||
          row.type;
        return <ElTag>{type}</ElTag>;
      },
    },
    {
      label: () => t("question-manage.question"),
      prop: "title",
      minWidth: 120,
      cellRender({ row }) {
        const parse = new DOMParser();
        const title = parse.parseFromString(row.title, "text/html").body
          .textContent;
        return <div>{title}</div>;
      },
    },
  ];
};
